package com.mercury.tests;

import com.mercury.beans.*;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.context.ApplicationContext;

public class IoCTest {
	public static void main(String[] args) {
		ApplicationContext actx = new FileSystemXmlApplicationContext("iocconfig.xml");
		User user = (User)actx.getBean("user");
		System.out.println(user);
		User user2 =(User)actx.getBean("user");
		System.out.println("user==user2? "+(user==user2));
		System.out.println("user.name==user2.name? "+(user.getName()==user2.getName()));  //shadow copy
		People people = (People)actx.getBean("people");
		System.out.println(people);
		
		Wrapper w1=(Wrapper)actx.getBean("w1");
		System.out.println(w1);
		
		Wrapper w2=(Wrapper)actx.getBean("w2");
		System.out.println(w2);
		
		MultiCollection mc =(MultiCollection)actx.getBean("multicoll");
		System.out.println("********List************");
			for(String l:mc.getList())
				System.out.println(l);
		System.out.println("********Set**************");
			for(Integer i:mc.getSet())
				System.out.println(i);
		System.out.println("********Map**************");
			for(int key:mc.getMap().keySet())
				System.out.println(key+"\t"+mc.getMap().get(key));		
		System.out.println("********Properties**************");
			for (Object key:mc.getProperties().keySet())
				System.out.println(key+"\t"+mc.getProperties().get(key));
		
		MySingle ms=(MySingle)actx.getBean("ms");
		ms.print();
		
		LazyBean lazyBean =(LazyBean)actx.getBean("lazyBean");
		lazyBean.print();
	}
}
